<?php
/**
 * Created by Allen.
 * Date: 15-10-15
 * 报价模型
 */

class Quote_model extends HS_Model {


    //获取结果集
    public function getQuoteList($where=array(), $limit='20', $offset='0', $order_by='id desc')
    {
    	return $this->select('quote.*,user.user_nick,vehicle.vehicle_owner,vehicle.phone,vehicle.vehicle_model,vehicle.car_num,vehicle.engine,vehicle.frame_num,vehicle.company_name,vehicle.create_time')
		->join('user','user.id = quote.user_id')
		->join('vehicle','vehicle.id = quote.vehicle_id')
    	->where($where)->limit($limit, $offset)->order_by($order_by)->find_all();
    }
    //获取结果集all
    public function getQuoteNext($where=array(), $order_by='id asc')
    {
        return $this->select('quote.*,user.user_nick,vehicle.vehicle_owner,vehicle.phone,vehicle.vehicle_model,vehicle.car_num,vehicle.engine,vehicle.frame_num,vehicle.company_name,vehicle.create_time')
        ->join('user','user.id = quote.user_id')
        ->join('vehicle','vehicle.id = quote.vehicle_id')
        ->where($where)->limit(1)->order_by($order_by)->find();
    }
    
    //计算行数
    public function getCount($where = array())
    {
    	return $this->select('quote.*,user.user_nick,vehicle.vehicle_owner,vehicle.phone,vehicle.vehicle_model,vehicle.car_num,vehicle.engine,vehicle.frame_num,vehicle.company_name,vehicle.create_time')
        ->join('user','user.id = quote.user_id')
        ->join('vehicle','vehicle.id = quote.vehicle_id')
        ->where($where)->count();
    }  
     
    //获取单个
    public function checkQuote($where)
    {
    	return $this->select('quote.*,vehicle.vehicle_owner,vehicle.phone,vehicle.vehicle_model,vehicle.car_num,vehicle.engine,vehicle.frame_num,vehicle.company_name,vehicle.create_time')
		->join('vehicle','vehicle.id = quote.vehicle_id')
    	->where($where)->find();
    }
    
    //删除
    public function deleteQuote($where)
    {
    	return $this->where($where)->delete();
    }
    
    //编辑
    public function editQuote($where,$data)
    {
    	return $this->where($where)->edit($data);
    }
    
    //添加
    public function addQuote($data)
    {
    	if ($this->add($data))
    	{
    		return $this->db->insert_id();
    	}
    }
}
?>
